<!doctype html>
<html>
<head>
    <title>Metric Stat</title>
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf8" />
    
    <link href='css/bootstrap.min.css' rel="stylesheet" />
    <link href="css/style.css" type="text/css" rel="stylesheet" />
    
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script src="js/lang.js" type="text/javascript" charset="utf8"></script>
    
    <script src="js/common.js" type="text/javascript" charset="utf8"></script>
</head>
<body>

    <div class="container-fluid">
        <div class="row-fluid">
            <div class="span12">
                <h3 style="display:inline;">
                    Metric Stat
                    <a href="metric.json" target="_blank" class="lang"  langKey="ViewJSONAPI"></a>
                    <span style="font-size:50%;font-weight:100;">
                        ${(dubboProvider.toNameString())!}
                    </span>
                </h3>

                <table id="dataTable" class="table table-bordered table-striped responsive-utilities">
                    <thead>
                        <tr>
                            <th>N</th>
                            <th>
                                <a id="th-Method" href="javascript:void(0);" class="lang" langKey="Method">Method</a>
                            </th>
                            <th>
                                <a id="th-ExecuteCount" href="javascript:void(0);" class="lang" langKey="ExecuteCount">ExecuteCount</a>
                            </th>
                            <th>
                                <a id="th-ExecuteTimeMillis" href="javascript:void(0);" class="lang" langKey="ExecuteTimeNanos">ExecuteTimeNanos</a>
                            </th>
                            <th>
                                <a id="th-RunningCount" href="javascript:void(0);" class="lang" langKey="RunningCount">RunningCount</a>
                            </th>
                            <th>
                                <a id="th-ConcurrentMax" href="javascript:void(0);" class="lang" langKey="ConcurrentMax">ConcurrentMax</a>
                            </th>
                        </tr>
                    </thead>

                    <tbody></tbody>
                </table>
            </div>
        </div>
    </div>
    <script type="text/javascript">
                    $.namespace("druid.metric");

                    druid.metric = function() {
                        return {
                            init : function() {
                                $("#dataTable th a").click(function(obj) {
                                    druid.common.setOrderBy(obj.target.id.substring(3))
                                })

                                druid.common.buildHead(8);
                                druid.common.ajaxuri = 'metric.json?';
                                druid.common.handleAjaxResult = druid.metric.handleAjaxResult;
                                druid.common.ajaxRequestForBasicInfo();
                            },

                            handleAjaxResult : function(data) {
                                var sqlStatTable = document.getElementById("dataTable");
                                while (sqlStatTable.rows.length > 1) {
                                    sqlStatTable.deleteRow(1);
                                }

                                var html = "";
                                for (var i = 0; i < data.length; i++) {
                                    var stat = data[i];
                                    var newRow = sqlStatTable.insertRow(-1);

                                    var methodName = stat.InterfaceMethod || stat.Method;
                                    methodName = methodName ? druid.common.subUriString(methodName, 150) : "";

                                    html += "<tr>";

                                    html += '<td>';
                                    html += (i + 1);

                                    if (stat.graph) {
	                                    html += " <a title=\"点击查看折线图\" target=\"_blank\" href=\"line-graph?type=METRIC&key=" + encodeURI(stat.key) + "\">~</a>";
                                    }

                                    html += "</td>";

                                    var methodHref = "../../#metric?metricKey=" + stat.key + "&host=" + druid.common.host() + "&port=" + druid.common.port();

                                    html += "<td>" //
                                        + "<a title='查看关联' target='_blank' href='" + methodHref + "'>+ </a>" // 
                                        + stat.key // 
                                        + "</td>";

                                    html += "<td>" + replace(stat.executeCount) + "</td>";
                                    html += "<td>" + replace(stat.executeTimeNanos) + "</td>";
                                    html += "<td>" + replace(stat.RunningCount) + "</td>";
                                    html += "<td>" + replace(stat.ConcurrentMax) + "</td>";
                                    html += "</tr>";
                                }

                                $("#dataTable tbody").html(html);
                                druid.common.stripes();
                            }
                        }
                    }();

                    $(document).ready(function() {
                        druid.metric.init();
                    });
                </script>
</body>
</html>